package pl.edu.agh.neuraleconomy.ui;

import org.apache.log4j.Logger;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import pl.edu.agh.neuraleconomy.ui.component.MainWindow;
import pl.edu.agh.neuraleconomy.ui.util.UIUtils;

public class App {

	private static Logger logger = Logger.getLogger(App.class);

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		Context.put(Context.SHELL, shell);
		prepareUI(shell);
		shell.pack();
		shell.open();

		while (!shell.isDisposed()) {
			try {
				if (!display.readAndDispatch())
					display.sleep();
			} catch (Exception e) {
				logger.error("", e);
				UIUtils.showError(e.getMessage());
			}
		}
		display.dispose();

	}

	private static void prepareUI(Shell shell) {
		shell.setLayout(new GridLayout(1, false));
		MainWindow window = new MainWindow(shell, SWT.NONE);
		window.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	}

}
